<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<html>
	<head>
	<base target="_self" />
		<title>选择盘口页面</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		
		<script type="text/javascript" src="${ctx}/js/jquery.js" ></script>	
		
		<script type="text/javascript">
			function closeWin(){
				window.close();
			}
			function hiddenIt(){
				$("select").each(function(){
					this.selectedIndex=0;
				});
			
				$("input:text").each(function(){
					this.value="";
				}); 
				document.getElementById("addNewHandicap").style.display="none";
			}
			
			function addHandicap(){
				 document.getElementById("addNewHandicap").style.display="";
			}
			
			function getHandicapInfo(){
				var handicapInfo = $("#selectedValue").attr("value");
				
				if(handicapInfo != null && handicapInfo != ""){
					window.returnValue = handicapInfo;
					window.close();
				}
				else{
					var confirmMessage = "you should select a record!";
					alert(confirmMessage);
				}
			
			}
			
			function changeSelectValue(value){
				$("#selectedValue").attr("value",value);
			}
			
			function opttxt_onkeypress(e)
	 		{
		 		var key=window.event ?e.keyCode:e.which;
		 		var keycode = String.fromCharCode(key);
		 		if(key==8||key==46) {   
		            return true;   
		        }  
				reg = /\d|\.|-/;
			 	return reg.test(keycode);
	 		}
			
			function saveHandicap(){
			
				var betCompanyId = document.getElementById("betCompany").value;
				var homeClbRate = document.getElementById("homeClbRate").value;
				var handicapTypeId = document.getElementById("handicapType").value;
				var awayClbRate = document.getElementById("awayClbRate").value;
				var matchId = '${matchId}';
				var url="list-handicap!add.action";
				var parm={MatchId:matchId,BetCompanyId:betCompanyId,AwayClbRate:awayClbRate,HomeClbRate:homeClbRate,HandicapTypeId:handicapTypeId};
				
				$.ajax({
		   	 		url:url,
		    		data:parm,
		    		success: function(page){
		    			$("#allHandicap").html(page);
		    		}
				});
				$("select").each(function(){
					this.selectedIndex=0;
				});
			
				$("input:text").each(function(){
					this.value="";
				}); 
				document.getElementById("addNewHandicap").style.display="none";
			}
		</script>
	</head>

	<body>
		<table>
			<table id="allHandicap" name="allHandicap">
			<table >
				<tr>
				  	<td>公司：</td>
				    <td>主队：</td>
				    <td>主队水率：</td>
				    <td>盘口：</td>
				    <td>客队：</td>
				    <td>客队水率：</td>
				    <td>跟新时间：</td>
				 </tr>
				  <c:forEach items="${handicapList}" var="handicapList" varStatus="status">
				  	<tr>
				  		<td>${handicapList.dqBetCompany.cmpyNameSc }</td>
				    	<td>${handicapList.dqMatch.dqClubsByHomeClbId.clbSc }</td>
				    	<td>${handicapList.homeClbRate }</td>
				    	<td>${handicapList.dqHandicapType.description }</td>
				    	<td>${handicapList.dqMatch.dqClubsByAwayClbId.clbSc }</td>
				    	<td>${handicapList.awayClbRate }</td>
				    	<td>${handicapList.updatedDt }</td>
				    	<td>
				    		<input type="radio" name="chooseHandicap" id="chooseHandicap" onclick="changeSelectValue(this.value);" value="${handicapList.hdpId},${handicapList.dqHandicapType.description },${handicapList.homeClbRate },${handicapList.awayClbRate }"/>
				    		<input type="hidden" name="selectedValue" id="selectedValue" value=""/>
				    	</td>
				  	</tr>
				  </c:forEach>
			</table>
			</table>
			<table>
				<tr>
					<td colspan="2">
						<a href="#" onclick="addHandicap()">添加新盘口</a>
					</td>
				</tr>
				<tr id="addNewHandicap" style="display: none">
					<td>公司信息</td>
					<td>
						<select name="betCompany" id="betCompany">
							<option value="">Select One</option>
								<c:forEach var="betCompanyList" items="${dqBetCompanyList}">
									<option value="${ betCompanyList.cmpyId}"> ${ betCompanyList.cmpyNameSc}</option>
								</c:forEach>
						</select>
					</td>
					<td>主队赔率</td>
					<td><input type="text" id="homeClbRate" name="homeClbRate" onkeypress="return opttxt_onkeypress(event);" /></td>
					<td>盘口信息</td>
					<td>
						<select name="handicapType" id="handicapType">
							<option value="">Select One</option>
								<c:forEach var="handicapTypeList" items="${dqHandicapTypeList}">
									<option value="${ handicapTypeList.hdpTypeId}"> ${ handicapTypeList.description}</option>
								</c:forEach>
						</select>
					</td>
					<td>客队赔率</td>
					<td><input type="text" id="awayClbRate" name="awayClbRate"  onkeypress="return opttxt_onkeypress(event);" /></td>
				
					<td>
						<input type="button" value="添加" id="Submit" onclick="saveHandicap()"/>
						<input type="button" value="取消" id="Cancel" onclick="hiddenIt()"/>
					</td>
					
				</tr>
			</table>
			<table>
				<tr>
					<td>
						<input type="button" value="确定" id="Submit" onclick="getHandicapInfo()"/>
						<input type="button" value="取消" id="Cancel" onclick="closeWin()"/>
					</td>
				</tr>
			</table>
		<table>
	</body>
</html>
